<?php
/**
 * @param id
 */
require_once('rb.php');
R::setup('mysql:host=ftp.giemiebier.nl:3306;dbname=personify', 'school', 'admin123');

//$return = array();

if ($pagetree[2] != "" && isset($pagetree[2])){
    $id = $pagetree[2];
}else{
    $id = "";
}

$return = getProfile($id);

echo json_encode($return);

function getProfile($id){
    if(R::count('profile', 'userid=?',array($id)) > 0) {
        $info = R::findOne("profile","userid=?",array($id)); //profile.countryid=countries.id
        $info['country'] = R::getRow("SELECT name, alpha_2 FROM countries WHERE id=?",array($info['countryid']));
        $info = json_decode($info);
    }
    else {
        $info["error"] = "Profile doesn't exist";
    }
    return $info;
}
?>
